﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using SMSSnew.smss_web_reference;
using SMSSnew.CLASSES;

namespace SMSSnew.DATA
{
    public class ShortLeaveDA
    {
        static smss_web_service_app srv = new smss_web_service_app();
        static readXML XMLreader = new readXML();

        static DataTable leaveTable = new DataTable();

        public string validateWhetherMoreThanThreeForParticularDay(DateTime Date)
        {
            string message = "";
            string query = "";
            try
            {
                query = XMLreader.readXMLtxt("validateWhetherMoreThanThreeForParticularDay", "~/DATA/XML/LeaveXML.xml");
                query = query.Replace("@REQUESTING_DATE", Date.ToString("yyyy/M/d"));

                leaveTable = srv.Search(query);

                if (leaveTable.Rows.Count >= 3)
                    message = "Three teachers have already requested short leaves for this day.";
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return message;
        }

        public string validateWhetherMoreThanTwoForMonth(DateTime Date, string teacher_id)
        {
            string message = "";
            string query = "";
            try
            {
                query = XMLreader.readXMLtxt("validateWhetherMoreThanTwoForMonth", "~/DATA/XML/LeaveXML.xml");
                query = query.Replace("@REQUEST_DATE", Date.ToString("yyyy/M/d"));
                query = query.Replace("@TEACHERID", teacher_id);

                leaveTable = srv.Search(query);

                if (leaveTable.Rows.Count >= 2)
                    message = "Sorry! You have already taken two short leaves for this month.";
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return message;
        }
    }
}
